﻿namespace ProblemsSet
{
    public class Problem_34 : BaseProblem
    {
        public override object GetResult()
        {
            var summ = 0;
            for (var i = 3; i < 1000000; i++)
            {
                long sm = 0;
                foreach (var b in MathLogic.GetDigits(i))
                {
                    sm += MathLogic.GetFactorial(b);
                    if (sm > i) break;
                }
                if (sm == i)
                {
                    summ += i;
                }
            }
            return summ;
        }

        public override string Problem
        {
            get
            {
                return @"145 is a curious number, as 1! + 4! + 5! = 1 + 24 + 120 = 145.

Find the sum of all numbers which are equal to the sum of the factorial of their digits.

Note: as 1! = 1 and 2! = 2 are not sums they are not included.";
            }
        }

        public override bool IsSolved
        {
            get
            {
                return true;
            }
        }

        public override object Answer
        {
            get
            {
                return 40730;
            }
        }

    }
}
